varying highp vec3 Normal;
varying highp vec3 FragPos;
varying highp vec2 TexCoords;

struct Material {
    sampler2D texture_diffuse1;
    sampler2D texture_specular1;
    highp float shininess;
};

struct Light {
    //vec3 position;
    highp vec3 direction;
    highp vec3 ambient;
    highp vec3 diffuse;
    highp vec3 specular;
};

uniform Light light;
uniform Material material;
uniform highp vec3 viewPos;

void main()
{
    highp vec3 diffuseTexColor = vec3(texture2D(material.texture_diffuse1,TexCoords));
    highp vec3 specularTexColor = vec3(texture2D(material.texture_specular1,TexCoords));
    // ambient
    highp vec3 ambient = light.ambient * diffuseTexColor;
    // diffuse
    highp vec3 norm = normalize(Normal);
    highp vec3 lightDir = normalize(-light.direction);
    highp float diff = max(dot(norm, lightDir), 0.0);
    highp vec3 diffuse = diff * light.diffuse * diffuseTexColor;
    // specular
    highp vec3 viewDir = normalize(viewPos - FragPos);
    highp vec3 reflectDir = reflect(-lightDir, norm);
    highp float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
    highp vec3 specular = spec * light.specular * specularTexColor;

    highp vec3 result = (ambient + diffuse + specular);
    gl_FragColor = vec4(result, 1.0);
}
